package org.xqp.user.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xqp.basic.exception.MyException;
import org.xqp.basic.util.JsonResult;
import org.xqp.user.service.IVerifycodeService;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifycodeController {

    @Autowired
    private IVerifycodeService verifycodeService;

    /**
     * Map接收参数
     * @return
     */
    @PostMapping("/smsCode")
    public JsonResult smsCode(@RequestBody Map<String,String> param){ // 接收前端传过来的参数 传过来的参数会被封装到map param中
        try {
            verifycodeService.smsCode(param); // 通过map  的key phone  获取value   这里的key和value是前端决定的
            return JsonResult.me();
        }catch (MyException e) {
            e.printStackTrace();
            return JsonResult.me().setMsg(e.getMessage());
        }
        catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("系统繁忙。。");
        }
    }
}
